﻿#include"SimulationParasWidget.h"
#include "ui_SimulationParasWidget.h"
#include "CompSelectComBoxWidget.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKComponents.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKEasyParam/FITKWidgetComLine.h"
#include "FITK_Kernel/FITKEasyParam/FITKWidgetVBox.h"
#include "FITK_Kernel/FITKEasyParam/FITKEasyParamWidgetFactory.h"
#include "FITK_Interface/FITKInterfaceFlowOF/FITKOFPhysicsData.h"
#include "FITK_Interface/FITKInterfaceFlowOF/FITKSimulationParameters.h"
#include "FITK_Kernel/FITKEasyParam/FITKParameter.h"
#include "FITK_Interface/FITKInterfaceFlowOF/FITKOFPhysicsManager.h"
#include "FITK_Interface/FITKInterfaceFlowOF/FITKFlowPhysicsHandlerFactory.h"
#include "FITK_Component/FITKWidget/FITKTabWidget.h"


namespace GUI
{

    SimulationParasWidget::SimulationParasWidget(EventOper::ParaWidgetInterfaceOperator * oper, QWidget * parent) :
        GUICalculateWidgetBase(oper, parent)
    {
        _ui = new Ui::SimulationParasWidget();
        _ui->setupUi(this);

        init();
    }

    SimulationParasWidget::~SimulationParasWidget()
    {
        if (_ui) delete _ui;
    }

    void SimulationParasWidget::init()
    {
        if (_physicsData == nullptr)return;
        _simuParas = _physicsData->getSimulationParameters();

        updateAction();
        updateCtrlParas();

    }

    void SimulationParasWidget::showEvent(QShowEvent * event)
    {
        Q_UNUSED(event);
        int width = _ui->tabWidget_2->width();
        int tabCount = _ui->tabWidget_2->count();
        int tabWidth = width / tabCount;
        _ui->tabWidget_2->tabBar()->setStyleSheet(QString("QTabBar::tab{width:%1px;height:30px;}").arg(tabWidth));
    }

    void SimulationParasWidget::resizeEvent(QResizeEvent * event)
    {
        Q_UNUSED(event);
        int width = _ui->tabWidget_2->width();
        int tabCount = _ui->tabWidget_2->count();
        int tabWidth = width / tabCount;
        _ui->tabWidget_2->tabBar()->setStyleSheet(QString("QTabBar::tab{width:%1px;height:30px;}").arg(tabWidth));
    }


    void SimulationParasWidget::updateAction()
    {
        if (_physicsData == nullptr)return;
        auto actionvalue = _simuParas->getAction();
        if (actionvalue == nullptr)return;
        for (auto v : actionvalue->getParameter()) {
            if (v == nullptr)continue;
            QWidget* widget = new Core::FITKWidgetComLine(v, this);
            _ui->verticalLayout_Action->addWidget(widget);
        }
    }

    void SimulationParasWidget::updateCtrlParas()
    {
        if (_physicsData == nullptr)return;
        auto ctrlparasvalue = _simuParas->getControlParameters();
        if (ctrlparasvalue == nullptr)return;
        for (auto v : ctrlparasvalue->getParameter()) {
            if (v == nullptr)continue;
            QWidget* widget = new Core::FITKWidgetComLine(v, this);
            _ui->verticalLayout_ControlParas->addWidget(widget);
        }
    }
}
